User blog:92garfield/Tutorial on creating Templates
I found it relatively hard to find an explanation on how to create a template and [[User:Lesanthosxia|'Leia - ']] [[User talk:Lesanthosxia|'零亜のレサンテョスイア™']] said it would be nice if I made a blog about this. Introduction The only thing I expect you to know before reading this is how to edit pages in general using existing templates, including such that need parameters as ( ). I recommend reproducing the examples on own sandboxes for better understanding. Creating a Template page A template page is created as any other page, you can create them on your sandbox for testing purposes. However when creating templates for public use, you should prefix it with "Template:" so it looks like Template:Pending_for_test but can be used as ( ). Example In the most simple template, the text on the template page replaces the so it shows as . Sorted Parameters Parameters are added after the template name, seperated by vertical lines (|) there is one line for each parameter, parameters can be anything you can write on the wiki sorted parameters are also anonymous parameters, they have no name. You call sorted parameters by their position, so the order in which you write them when using the template is important. The parameters are called by the position they are at, enclosed in triple { so the first parameter is used as }. By adding a vertical line (|) behind the number, you can give default values in case the parameter is not used. For empty default value it will look like }, when no default value is given and the parameter is not used it will show up as } so you should always state a default value. As I diddn't state that in requirements, you might be wondering "what the fuck do you mean by using parameters?". It's simple, the } in a template page will be replaced by whatever is written behind the first vertical line (|) when using the template. Examples Example 1 Will expand to: It got 3 Parameters each one got a default value. Example 2 Will expand to: Named Parameters Named parameters are mostly used for large templates or when they have many optional parameters. When parameters have names, the order doesn't matter it's used by first writeing the name behind a vertical line (|) and the value behind it seperated by a equal sign (=). Named and sorted parameters can be used in one template, for the names of the sorted ones the named ones are not counted. In the template the names are written instead of the numbers, default values are stated the same way as in sorted parameters. Example Expands to: Functions Now it gets intresting, functions behave based on parameters, they are used as , they work similarily with templates, but offer additional functionality. he amount of parameters varies, I'm only going to explain the most important functions (that's about oppinion of course). All functions are explained here (or somewhere around there). if The function takes three parameters. The term is expanded to either the second or third parameter based on wether the input is true or false. The input is considered true as long as it's not empty. A string that only contains spaces or line breaks it's considered empty as well. When the input is true, the therm expands to the second parameter, otherwise it will show the third parameter. Examples Example 1 Expands to: Example 2 Expands to: replace This function takes three parameters. The function will expand to the input, but all occurrences of the search term replaced with the replacement term. Example Expands to: Question & Answer Feel free to ask related questions in comments, in chat or as message to me. If I feel they could be intresting, more frequent or important in some other way, I will post and answer them here. I will however answer any question you ask me, given I know the answer. Work in progress This is gonna be continued the next days. *92Gar†ield~ 20:07, March 26, 2012 (UTC) Category:Blog posts